﻿using System;
using System.Text.RegularExpressions;

namespace BSpec
{
    public static class StringExtensions
    {
        public static string ReplaceUnderscoresWithSpace(this string value)
        {
            return value.Replace("_", " ");
        }

        public static string ReplaceDotWithSpace(this string value)
        {
            return value.Replace(".", " ");
        }

        public static string CapitaliseFirstLetter(this string value)
        {
            if (value.IsEmpty()) return value;

            return char.ToUpper(value[0]) + value.Substring(1);
        }

        public static bool IsEmpty(this string value)
        {
            return String.IsNullOrEmpty(value);
        }

        public static string ReplaceCamelCaseWithSpace(this string value)
        {
            return Regex.Replace(value, @"(\B[A-Z])", " $1", RegexOptions.Compiled).ToLower();
        }

        public static string ReplaceDoubleUnderscoresWithQuotes(this string value)
        {
            return Regex.Replace(value, @"(?<quoted>__(?<inner>\w+?)__)", " \"${inner}\" ");
        }

        public static string RemoveWhiteSpace(this string value)
        {
            return value.Replace(" ", string.Empty);
        }
    }
}
